import { createWebHistory, createRouter } from 'vue-router'
import Home from '../vies/home/home.vue'
import Login from '../vies/login.vue'
import Lb from '../vies/lb.vue'
import Fl from '../vies/home/fl.vue'
import Homelist from '../vies/home/homelist.vue'
import My from '../vies/home/my.vue'

const routes = [
    { path: '/', redirect: '/home/homelist' },
    {
        path: '/home',
        component: Home,
        children: [
            {
                path: 'fl',
                component: Fl,
            },
            {
                path: 'homelist',
                component: Homelist
            },
            {
                path: 'my',
                component: My,
            }
        ]
    },
    { path: '/login', component: Login },
    { path: '/lb', component: Lb },
]

export const router = createRouter({
    history: createWebHistory(),
    routes,
})
router.beforeEach((to, from) => {
    if (to.fullPath !== '/login') {
        const token = localStorage.getItem('token')
        if (!token) {
            return {
                path: '/login'
            }
        }
    }
})